//
//  WBSearchBar.m
//  微博项目
//
//  Created by huangchucai on 16/2/15.
//  Copyright © 2016年 com.foxconn.FuLearn. All rights reserved.
//

#import "WBSearchBar.h"
#import "UIImage+XHImage.h"

@interface WBSearchBar ()<UITextFieldDelegate>

@end

@implementation WBSearchBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame])
    {
        self.font = [UIFont systemFontOfSize:13*WidthScale>17?17:13*WidthScale];
        //self.background = [UIImage imageWithStretchableName:@"searchbar_textfield_background"];
        self.backgroundColor =RGBColor(249, 249, 250);
        //设置左边的view
        // initWithImage: 默认UIImageView的尺寸跟图片一样
        UIImageView  *imageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
        
        //imageV.xh_Width += 15;
    
        //imageV.xh_Width = 40;
        
        imageV.contentMode = UIViewContentModeCenter;
        self.leftView = imageV;
       //这个属性一定要设置，想要显示搜索框左边的view视图，一定要设置左边视图的模式，因为默认其为UITextFieldViewModeNever不显示的
        self.leftViewMode = UITextFieldViewModeAlways;
        self.tintColor = RGBColor(20, 133, 255);
        self.clearButtonMode = UITextFieldViewModeAlways;
    }
    
    return self;
}

-(CGRect)leftViewRectForBounds:(CGRect)bounds
{
    CGRect rect =[super leftViewRectForBounds:bounds];

    rect.origin.x = 5;

    return rect;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

@end
